package com.colorfruit.admin.control.controller;

import com.colorfruit.admin.business.service.LogicService;
import com.colorfruit.framework.model.pojo.BaseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RequestMapping("/logic")
@RestController
public class LogicController {

    @Autowired
    LogicService logicService;

    /**
     * 获取物流进度信息
     * @param pickAddressId
     * @return
     */
    @RequestMapping("/getLogicTransportInfo")
    public BaseResult getLogicTransportInfo(Long pickAddressId){
        log.info("# [IN] [controller] selectPurchaseCountList param: pickAddressId = {}", pickAddressId);
        BaseResult baseResult = logicService.getLogicTransportInfo(pickAddressId);
        log.info("# [OUT] [controller] selectPurchaseCountList SUCCESS");
        return baseResult;
    }

    /**
     * 添加司机
     * @param pickGoodsAddressId 拣货点地址ID
     * @param driver 司机姓名
     * @param phone 司机电话号码
     * @param carNumber 车牌号
     * @return
     */
    @RequestMapping("/addDriverInfo")
    public BaseResult addDriverInfo(Long pickGoodsAddressId, String driver, String phone, String carNumber){
        log.info("# [IN] [controller] addDriverInfo param: pickGoodsAddressId = {}, driver = {}, phone = {}, carNumber = {}",
                pickGoodsAddressId ,driver, phone, carNumber);
        BaseResult baseResult = logicService.addDriverInfo(pickGoodsAddressId, driver, phone, carNumber);
        log.info("# [OUT] [controller] addDriverInfo SUCCESS");
        return baseResult;
    }

    /**
     * 获取司机信息列表
     * @param pickAddressId 拣货点地址ID
     * @return
     */
    @RequestMapping("/selectDriverInfo")
    public BaseResult selectDriverInfo(Long pickAddressId){
        log.info("# [IN] [controller] selectDriverInfo param: pickAddressId = {}", pickAddressId);
        BaseResult baseResult = logicService.selectDriverInfo(pickAddressId);
        log.info("# [OUT] [controller] selectDriverInfo SUCCESS");
        return baseResult;
    }

    /**
     * 获取需要运输的产品信息列表
     * @param pickAddressId 拣货点地址ID
     * @return
     */
    @RequestMapping("/selectProductList")
    public BaseResult selectProductList(Long pickAddressId){
        log.info("# [IN] [controller] selectProductList param: pickAddressId = {}", pickAddressId);
        BaseResult baseResult = logicService.selectProductList(pickAddressId);
        log.info("# [OUT] [controller] selectProductList SUCCESS");
        return baseResult;
    }

    /**
     * 更新运输数量
     * @param logicTransportInfoId 物流进度信息ID getLogicTransportInfo的id字段
     * @param purchaseTotalAddressInfoId 统计采购订单id selectProductList的id字段
     * @param num 运输数量
     * @return
     */
    @RequestMapping("/updateTransportNum")
    public BaseResult updateTransportNum(Long logicTransportInfoId, Long purchaseTotalAddressInfoId, int num){
        log.info("# [IN] [controller] updateTransportNum param: logicTransportInfoId = {}, purchaseTotalAddressInfoId = {}, num = {}",logicTransportInfoId,  purchaseTotalAddressInfoId, num);
        BaseResult baseResult = logicService.updateTransportNum(logicTransportInfoId, purchaseTotalAddressInfoId, num);
        log.info("# [OUT] [controller] updateTransportNum SUCCESS");
        return baseResult;
    }

    /**
     * 生存物流单
     * @param logicTransportInfoId 物流进度信息ID getLogicTransportInfo的id字段
     * @return
     */
    @RequestMapping("/generateLogicInfo")
    public BaseResult generateLogicInfo(Long logicTransportInfoId){
        log.info("# [IN] [controller] updateTransportNum param: LogicTransportInfoId = {}", logicTransportInfoId);
        BaseResult baseResult = logicService.generateLogicInfo(logicTransportInfoId);
        log.info("# [OUT] [controller] updateTransportNum SUCCESS");
        return baseResult;
    }

}
